from PIL import Image
import os

folder_path = r'/cir_output'
output_folder = r'C:\pycharm_proj\svg_convert\converted'
os.makedirs(output_folder, exist_ok=True)

for filename in os.listdir(folder_path):
    if filename.lower().endswith('.png'):
        file_path = os.path.join(folder_path, filename)
        img = Image.open(file_path).convert('RGBA')
        pixels = list(img.getdata())

        new_pixels = []
        for px in pixels:
            if px == (0, 0, 0, 0):
                new_pixels.append((255, 255, 255, 255))  # 全为0，变白色
            else:
                new_pixels.append((0, 0, 0, 255))          # 否则变黑色

        # 创建新图像并保存
        new_img = Image.new('RGBA', img.size)
        new_img.putdata(new_pixels)
        output_path = os.path.join(output_folder, filename)
        new_img.save(output_path)

        print(f"{filename} 已处理并保存为 {output_path}")
